const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Question = {};

const questionSchema = new mongoose.Schema({
    _id: Schema.Types.ObjectId,
    title: String,
    content: String,
    createTime: Date,
    author: {
        type: Schema.Types.ObjectId,
        ref: 'users'
    },
    answers: [{ type: Schema.Types.ObjectId, ref: 'answers' }],
    readNum: {
        type: Number,
        default: 0
    }
})

Question.Model = mongoose.model('questions', questionSchema)

Question.Model.on('index', err => {
    if (err) {
        console.error('集合 keywords 索引错误！', err)
    } else {
        console.log('集合 Question 索引成功...')
    }
})

module.exports = Question;
